#include "DXUT.h"
#include "RandomMwc.h"

RandomMwc    g_randomMwc;

/// constants ------------------------------------------------------------------
namespace
{
   // default seeds
   const unsigned int SEEDS[2] = { 521288629u, 362436069u };
}

RandomMwc::RandomMwc
(
   const int seed
)
{
   seeds_m[0] = (0 != seed) ? static_cast<unsigned int>(seed) : SEEDS[0];
   seeds_m[1] = (0 != seed) ? static_cast<unsigned int>(seed) : SEEDS[1];
}

int RandomMwc::getDword()
{
    seeds_m[0] = 18000u * (seeds_m[0] & 0xFFFFu) + (seeds_m[0] >> 16);
    seeds_m[1] = 30903u * (seeds_m[1] & 0xFFFFu) + (seeds_m[1] >> 16);
    return static_cast<int>( (seeds_m[0] << 16) + (seeds_m[1] & 0xFFFFu) );
}


float RandomMwc::getFloat()
{
   return static_cast<float>(static_cast<unsigned int>(getDword())) / 4294967296.0f;
}
